import javax.xml.transform.OutputKeys;
import java.util.Random;
import java.util.Scanner;

public class CPUGuessGame {
    static Random r = new Random();
    //The main
    public static void main(String[] args) {
        System.out.println("I want to play a guessing game where I guess your number.");
        System.out.println("Think of your number now (between 1 and 30, and I will guess it. Ready? Enter 1 to start");
        int a;
        Scanner input= new Scanner(System.in);
        a=input.nextInt();
        if(a==1){
            System.out.println("Is your number 15? Press 1 for yes and 2 for no.");
            YesNo(1);
        }
        else{
            System.out.println("Well then why did you play?");
            System.out.println("Good bye.");
        }
    }
    //Universal Method for asking Yes or No
    public static void YesNo(int whatmethod){
        if(whatmethod==1){
        Scanner input= new Scanner(System.in);
        int a=input.nextInt();
        if (a==1)
            Secondguessforward(1);
        else
            Secondguessforward(2);
        }
        if(whatmethod==2){
            Scanner input= new Scanner(System.in);
            int b=input.nextInt();
            if(b==1)
                Secondguessforward(3);
            else
                Secondguessforward(4);
        if(whatmethod==3){
            Scanner in= new Scanner(System.in);
            int d=in.nextInt();
            if(d==1)
                CPUWin();
            if(d==2)
                Secondguessforward(5);
        }
        if(whatmethod==4){
            Scanner input1= new Scanner(System.in);
            int c=input1.nextInt();
            if(c==1)
                CPUWin();
            if(c==2)
                Secondguessforward(6);
        }
        if(whatmethod==5){
            Scanner input3= new Scanner(System.in);
            int e=input3.nextInt();
            if(e==1)
                Secondguessforward(7);
            if(e==2)
                Secondguessforward(8);
        }

        if(whatmethod==6){
            Scanner input2= new Scanner(System.in);
            int f=input2.nextInt();
            if(f==1)
                Secondguessforward(9);
            if(f==2)
                Secondguessforward(10);
        }
         if(whatmethod==7){
             Scanner input3= new Scanner(System.in);
             int g=input3.nextInt();
             if(g==1)
                 CPUWin();
             if(g==2)
                 Secondguessforward(11);
         }
         if(whatmethod==8){
             Scanner input4= new Scanner(System.in);
             int h=input4.nextInt();
             if(h==1)
                 CPUWin();
             if(h==2)
                 Secondguessforward(12);
         }
         if(whatmethod==9){
             Scanner input5= new Scanner(System.in);
             int i=input5.nextInt();
             if(i==1)
                 CPUWin();
             if(i==2)
                 Secondguessforward(13);
         }
         if(whatmethod==10){
             Scanner input6= new Scanner(System.in);
             int j=input6.nextInt();
             if(j==1)
                 CPUWin();
             if(j==2)
                 Secondguessforward(14);
         }
         if(whatmethod==11){
             Scanner input7= new Scanner(System.in);
             int k=input7.nextInt();
             if(k==1)
                Secondguessforward(15);
             if(k==2)
                 Secondguessforward(16);
         }
         if(whatmethod==12){
             Scanner input8= new Scanner(System.in);
             int l=input8.nextInt();
             if(l==1)
                 Secondguessforward(17);
             if(l==2)
                 Secondguessforward(18);
         }
         if(whatmethod==13){
             Scanner input9= new Scanner(System.in);
             int m=input9.nextInt();
             if(m==1)
                 Secondguessforward(19);
             if(m==2)
                 Secondguessforward(20);
         }
         if(whatmethod==14){
             Scanner input10= new Scanner(System.in);
             int n=input10.nextInt();
             if(n==1)
                 Secondguessforward(21);
             if(n==2)
                 Secondguessforward(22);
         }
         if(whatmethod==15){
             Scanner in= new Scanner(System.in);
            int o=in.nextInt();
            if(o==1)
                CPUWin();
            if(o==2)
                CPULose();
        }
    }}
    public static void Secondguessforward(int whatpart){
        if(whatpart==1){
            CPUWin();
        }
        if(whatpart==2){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(2);
        }
        if(whatpart==3){
            System.out.println("OK, this next guess will be lower.");
            System.out.println("Is your number 8? 1 for yes, 2 for no.");
            YesNo(3);
        }
        if(whatpart==4){
            System.out.println("OK, this next guess will be higher.");
            System.out.println("Is your number 22? 1 for yes, 2 for no.");
            YesNo(4);
        }
        if(whatpart==5){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(5);
    }
        if(whatpart==6){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(6);
        }
        if(whatpart==7){
            System.out.print("OK...is your number 4? 1 for yes, 2 for no.");
            YesNo(7);
        }
        if(whatpart==8){
            System.out.print("OK...is your number 12? 1 for yes, 2 for no.");
            YesNo(8);
        }
        if(whatpart==9){
            System.out.print("OK...is your number 18? 1 for yes, 2 for no.");
            YesNo(9);
        }
        if(whatpart==10){
            System.out.print("OK...is your number 26? 1 for yes, 2 for no.");
            YesNo(10);
        }
        if(whatpart==11){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(11);
        }
        if(whatpart==12){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(12);
        }
        if(whatpart==13){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(13);
        }
        if(whatpart==14){
            System.out.println("Well was that too high or too low? 1=Too high. 2=Too low");
            YesNo(14);
        }
        if(whatpart==15){
            int guess=r.nextInt(4) +4;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==16){
            int guess=r.nextInt(3) +1;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==17){
            int guess=r.nextInt(4) +12;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==18){
            int guess=r.nextInt(4) +8;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==19){
            int guess=r.nextInt(4) +19;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==20){
            int guess=r.nextInt(3) +16;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==21){
            int guess=r.nextInt(4) +27;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }
        if(whatpart==22){
            int guess=r.nextInt(4) +23;
            System.out.print("OK...is your number "+guess+"? Press 1 for Yes, 2 for No.");
            YesNo(15);
        }

    }
    public static void CPUWin(){
        System.out.println("Good game, user.");
        System.exit(0);
    }
    public static void CPULose(){
        System.out.print("Oh well, that was fun. Good game!");
        System.exit(0);
    }
}